<import file="block/common.html" name="url" :tpl_cfg="['urlName'=>'视频栏目']"/>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
		<table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>
		<script type="text/html" id="toolbarAE">
			<div class="layui-form">
				<?php echo SysRolCk("contentcate_add")?'<button class="layui-btn layui-btn-sm data-add-btn"><i class="layui-icon">&#xe61f;</i>'.lang('add').' </button>':''; ?>
			</div>
		</script>
		<script type="text/html" id="icoTableBar">
			<i class="layui-icon {{d.ico}}"></i> 
		</script>

		<script type="text/html" id="contentUrlTpl">
			<a href="/videos/{{d.id}}" target="_blank">{{d.name}}</a>			
	    </script>

		<script type="text/html" id="currentTableBar">
			<div class="layui-btn-group">
				<?php echo SysRolCk("videocate_edit")?'<a class="layui-btn layui-btn-sm data-count-edit" lay-event="edit"><i class="layui-icon">&#xe642;</i>'.lang('edit').'</a>':'<a class="layui-btn layui-btn-disabled">'.lang('edit').'</a>'; ?>
				<?php echo SysRolCk("videocate_del")?'<a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</a>':'<a class="layui-btn layui-btn-xs layui-btn-disabled">删除</a>'; ?>
			</div>	
		</script>
		</div>
	</div>

</div>

<script>
	layui.define(function () {
		var $ = layui.jquery,
			table = layui.table,
			form = layui.form;

		table.render({
			elem: '#currentTableId',
			toolbar: '#toolbarAE',
			url: '<{CAUrl("videocate","index")}>&list_json',
			lineStyle: 'height: 40px;',//设置行样式 
			cols: [[
				//{type: "checkbox", width: 50, fixed: "left"},
				{ field: 'id', title: 'ID', width: 50 },
				{ field: 'name', title: '栏目名称', width: 260 , templet: '#contentUrlTpl'},
				{ field: 'sort', title: '排序',width: 60, edit: 'text'},
				{ field: 'theme', title: '模板'},
				{ field: 'num', title: '前台条数',width: 120},
				{ field: 'ico', title: '图标',width: 80, minWidth: 50, templet: '#icoTableBar', align: "center" },
				{ title: '操作', minWidth: 140,width: 220, templet: '#currentTableBar', fixed: "right", align: "center" }
			]],
			page: false,
			id: 'tableReload'
		});

		$(".data-add-btn").on("click", function () {
			loadMain('<{CAUrl("videocate","add")}>&view');
			return false;
		});

		//监听单元格编辑
        table.on('edit(currentTableFilter)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            $.post('<{CAUrl("videocate","edit")}>&sortedit&id=' + data.id, {sort:value}, function (res) {
				if (res.status == 1) {
					layer.msg(res.info, { icon: 1, time: 1000 }, function () {
						table.reloadData('tableReload');
					});
				} else {
					layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
				}
            });
        });


		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			if (obj.event === 'edit') {
				loadMain('<{CAUrl("videocate","edit")}>&view&id=' + data.id);
				return false;
			} else if (obj.event === 'delete') {
				layer.confirm('删除确认？', function (index) {
					$.post('<{CAUrl("videocate","del")}>', data, function (res) {
						if (res.status == 1) {
							layer.msg(res.info, { icon: 1, time: 1000 }, function () {
								obj.del();
								layer.close(index);
							});
						} else {
							layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
						}
					});
				});
			}
		});
	});

</script>